import pytest

@pytest.fixture(scope="session")
def session_fixture():
    print("\nSession级别的fixture: 在测试会话开始时运行一次")
    yield
    print("\nSession级别的fixture: 在测试会话结束时运行一次")

@pytest.fixture(scope="class")
def class_fixture():
    print("\nClass级别的fixture: 在每个测试类开始时运行一次")
    yield
    print("\nClass级别的fixture: 在每个测试类结束时运行一次")

@pytest.fixture(scope="function")
def function_fixture():
    print("\nFunction级别的fixture: 在每个测试函数开始时运行一次")
    yield
    print("\nFunction级别的fixture: 在每个测试函数结束时运行一次")

def test_case_1(session_fixture, class_fixture, function_fixture):
    print("\n执行测试用例1")

@pytest.mark.usefixtures("session_fixture", "class_fixture", "function_fixture")
class TestScopeTest:
    def test_case_2(self):
        print("\n执行测试用例2")

    def test_case_3(self):
        print("\n执行测试用例3")

if __name__ == "__main__":
    pytest.main(["-q", "pytest_study/pytest_fixture_scope_test.py"])
    # -q: 显示print输出内容